-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Repeatable Sections #10
base: master
Are you sure you want to change the base?
Conversation
Hi russ1985, I am going to be taking charge of approving pull requests. I'll be merging in my changes in the next couple of days, which might generate a couple of minor conflicts for you. Sorry, hope it's nothing too bad. Also, could you add a couple tests? We are using Rspec. This ensures that everything works, as well as provides everyone with examples of how to use your features. |
Yea, after I did the pull request I just thought "shouldn't I have added On 8/6/12 4:36 PM, Scott Berkley wrote:
|
I guess I'm also a bit confused about what the purpose of this change is. The code currently allows repeated sections. Is it important for your application that they get put into separate namespaces in the resulting parse object? |
I must have missed that, from what I saw it did not support repeating On 8/7/12 1:07 PM, Scott Berkley wrote:
|
parser.rb line 8
|
No special specification is needed. Sections are assigned by the 'trap' statement. So I can define my header section as a line that starts with 'HEAD'. Now if I have this file:
I will have two items in the header section, even though they don't come sequentially. They just get added to the array for that section, the same way that body lines do. I'm not really sure what the intention of that mode comment is. Give it a try and let me know if it doesn't do what you need it to. |
I might be confused then.. from what I see in the code it reads the sections linearly so if you have a definition of
and a file of
It would raise
because it would find another data record instead of a footer record. make sense? I hope I am not confusing you more. I only added my repeatable sections because I ran into the problem above and kept getting
It might seem odd, but I have some requirements for something like that. |
Oh, you're right, sorry. It turns out that we added repeatable sections in my change without my realizing it. We only deal with one section, so these issues are not on the top of my mind. My coworker changed how lines get added to sections to support parsing from IO objects, then I changed how the required section validation works because I saw that it didn't make sense any longer. It now parses all lines into sections, then checks to make sure all required sections have at least one row at the end. So the order of definition doesn't matter. I did the merge on my stuff, so try pulling the latest and see if it works for you. If you have sections of different lengths like in your example, you'll have to change the definition to |
I gave your example a try and might have fixed some things that were causing it to fail.
Gives me {:header=>[{:header_begin=>1, :batch_number=>1}], :data=>[{:data_begin=>2, :record_number=>1, :record_number_plus_batch=>1001, :id=>1, :name=>"Russell"}, {:data_begin=>2, :record_number=>2, :record_number_plus_batch=>2001, :id=>2, :name=>"Jim"}, {:data_begin=>2, :record_number=>3, :record_number_plus_batch=>3001, :id=>3, :name=>"Bill"}, {:data_begin=>2, :record_number=>1, :record_number_plus_batch=>1001, :id=>4, :name=>"Tim"}, {:data_begin=>2, :record_number=>2, :record_number_plus_batch=>2001, :id=>5, :name=>"Josh"}], :tail_record=>[{:tail_record_begin=>3, :num_records=>3}, {:tail_record_begin=>3, :num_records=>2}], :footer=>[{:footer_record_begin=>4, :total_record_count=>5, :batch_number=>1}]} Note that we also added length validation, so make sure each line is padded with spaces to make it the right length. Does this output work for you? |
That looks good to me, one question though, how will it write the file Thanks! On 8/8/12 10:05 AM, Scott Berkley wrote:
|
I'll let you test that out. I would guess it will write all headers, all data, all tails, and then all footers, so probably not what you want. If that's the case, we can figure out a solution. |
I wrote some specs to test my changes, you can see them in my commit. I thanks! On Wed, Aug 8, 2012 at 2:22 PM, Scott Berkley [email protected]:
|
Added ability to handle repeating sections.